﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPageMcSigAdmin.master" AutoEventWireup="true"
    CodeFile="Vehiculos.aspx.cs" Inherits="Vehiculos" %>

<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dx" %>

<%@ Register assembly="UsrControls" namespace="UsrControls" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table>
        <tr>
            <td>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                     </ContentTemplate>
                </asp:UpdatePanel>
                        <asp:Label ID="lblMensaje" runat="server" Font-Size="Medium" ForeColor="Red"></asp:Label>
                        <cc1:msgBox ID="msgBox1" runat="server" />
                        <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
                            DataSourceID="SqlDataSourceVehiculos" 
                            EnableTheming="True" KeyFieldName="AVE_ID" 
                            onrowcommand="ASPxGridView1_RowCommand" 
                            onrowinserted="ASPxGridView1_RowInserted" 
                            onrowupdated="ASPxGridView1_RowUpdated" 
                            onrowupdating="ASPxGridView1_RowUpdating" Theme="PlasticBlue" 
                    Width="100%">
                            <Columns>
                                <dx:GridViewDataTextColumn VisibleIndex="0">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewCommandColumn Caption="Opciones" VisibleIndex="1">
                                    <ClearFilterButton Visible="True" />
                                    <EditButton Visible="True">
                                    </EditButton>
                                    <NewButton Visible="True">
                                    </NewButton>
                                    <DeleteButton Visible="True">
                                    </DeleteButton>
                                </dx:GridViewCommandColumn>
                                <dx:GridViewDataTextColumn Caption="Id" FieldName="AMA_ID" Visible="False" 
                                    VisibleIndex="2">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn Caption="Placa" FieldName="AMA_PLACA" 
                                    VisibleIndex="3">
                                    <PropertiesTextEdit>
                                        <ValidationSettings CausesValidation="True">
                                        </ValidationSettings>
                                    </PropertiesTextEdit>
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn Caption="Dias Restantes SOAT" 
                                    FieldName="DIAS_RESTANTES_SOAT" VisibleIndex="5">
                                    <DataItemTemplate>
                                        <table style="width: 100%;">
                                            <tr>
                                                <td align="left" valign="top">
                                                    <asp:Image ID="Image1" runat="server" ImageUrl="Imagenes/Botverde.gif" 
                                                        Visible='<%# (Convert.ToDecimal(Eval("DIAS_RESTANTES_SOAT")) > 15 &&   Convert.ToDecimal(Eval("ATV_ID")) == 2) ? true:  false %>' />
                                                    <asp:Image ID="Image2" runat="server" ImageUrl="Imagenes/Botamarillo.gif" 
                                                        Visible='<%# (Convert.ToDecimal(Eval("DIAS_RESTANTES_SOAT")) >= 0 && Convert.ToDecimal(Eval("DIAS_RESTANTES_SOAT")) < 15 &&   Convert.ToDecimal(Eval("ATV_ID")) == 2)  ? true:  false %>' />
                                                    <asp:Image ID="Image3" runat="server" ImageUrl="Imagenes/Botrojo.gif" 
                                                        Visible='<%# (Convert.ToDecimal(Eval("DIAS_RESTANTES_SOAT")) < 0 &&   Convert.ToDecimal(Eval("ATV_ID")) == 2)  ? true:  false %>' />
                                                </td>
                                                <td align="center" valign="top">
                                                    <asp:Label ID="label1" runat="server" 
                                                        Text='<%# Eval("DIAS_RESTANTES_SOAT")  %>'></asp:Label>
                                                </td>
                                            </tr>
                                        </table>
                                    </DataItemTemplate>
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataComboBoxColumn Caption="Marca" FieldName="AMA_ID" 
                                    VisibleIndex="4">
                                    <PropertiesComboBox DataSourceID="SqlDataSourceMarcas" TextField="AMA_NOMBRE" 
                                        ValueField="AMA_ID" ValueType="System.String">
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                                <dx:GridViewDataComboBoxColumn Caption="TRAILER" FieldName="AVE_ID_TRAILER" 
                                    VisibleIndex="4">
                                    <PropertiesComboBox DataSourceID="SqlDataSourceTrailer" TextField="AMA_PLACA" 
                                        ValueField="AVE_ID_TRAILER" ValueType="System.String">
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                                <dx:GridViewDataComboBoxColumn Caption="Tipo Vehiculo" FieldName="ATV_ID" 
                                    VisibleIndex="6">
                                    <PropertiesComboBox DataSourceID="SqlDataSourceTipoVehiculos" 
                                        TextField="ATV_NOMBRE" ValueField="ATV_ID" ValueType="System.String">
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                                <dx:GridViewDataTextColumn Caption="Cert. Habilitación" 
                                    FieldName="AVE_CERT_HABILITACION" VisibleIndex="7">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn Caption="Serie Chasis" FieldName="AVE_SERIE_CHASIS" 
                                    VisibleIndex="8">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataDateColumn Caption="Fecha Fabricación" 
                                    FieldName="AVE_FECHA_FABRICACION" VisibleIndex="9">
                                </dx:GridViewDataDateColumn>
                                <dx:GridViewDataTextColumn Caption="Soat Expedición" FieldName="AVE_SOAT" 
                                    VisibleIndex="10">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn Caption="Compañia de Seguros" 
                                    FieldName="AVE_COMPANIA_SEGUROS" Visible="False" VisibleIndex="11">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataDateColumn Caption="Soat Vencimiento" 
                                    FieldName="AVE_VENCIMIENTO_SOAT" VisibleIndex="12">
                                </dx:GridViewDataDateColumn>
                                <dx:GridViewDataDateColumn Caption="Vencimiento Tecnomecanica" 
                                    FieldName="AVE_VENCE_REVISION_TECNOMECANICA" VisibleIndex="13">
                                </dx:GridViewDataDateColumn>
                                <dx:GridViewDataTextColumn Caption="Pais" FieldName="AVE_PAIS" 
                                    VisibleIndex="14">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataComboBoxColumn Caption="Aseguradora" FieldName="ACD_ID" 
                                    VisibleIndex="15">
                                    <PropertiesComboBox DataSourceID="SqlDataSourceAseguradoras" 
                                        TextField="ACD_NOMBRE" ValueField="ACD_ID" ValueType="System.String">
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                                <dx:GridViewDataComboBoxColumn Caption="Configuración" FieldName="ACO_ID" 
                                    VisibleIndex="16">
                                    <PropertiesComboBox DataSourceID="SqlDataSourceAutConfiguracion" 
                                        IncrementalFilteringMode="Contains" TextField="ACO_DESCRIPCION" 
                                        ValueField="ACO_ID" ValueType="System.String">
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                                <dx:GridViewDataComboBoxColumn Caption="Línea" FieldName="ALI_ID" 
                                    VisibleIndex="17">
                                    <PropertiesComboBox DataSourceID="SqlDataSourceAutLinea" 
                                        IncrementalFilteringMode="Contains" TextField="ALI_NOMBRE" ValueField="ALI_ID" 
                                        ValueType="System.String">
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                                <dx:GridViewDataComboBoxColumn Caption="Tipo Combustible" FieldName="ATC_ID" 
                                    VisibleIndex="18">
                                    <PropertiesComboBox DataSourceID="SqlDataSourceAutTipoCombustible" 
                                        IncrementalFilteringMode="Contains" TextField="ATC_DESCRIPCION" 
                                        ValueField="ATC_ID" ValueType="System.String">
                                        <ValidationSettings CausesValidation="True">
                                        </ValidationSettings>
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                                <dx:GridViewDataComboBoxColumn Caption="Color" FieldName="ACL_ID" 
                                    VisibleIndex="19">
                                    <PropertiesComboBox DataSourceID="SqlDataSourceAutColor" 
                                        IncrementalFilteringMode="Contains" TextField="ACL_DESCRIPCION" 
                                        ValueField="ACL_ID" ValueType="System.String">
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                                <dx:GridViewDataTextColumn Caption="Peso Vacio" FieldName="AVE_PESO_VACIO" 
                                    VisibleIndex="20">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataComboBoxColumn Caption="Tercero" FieldName="APE_ID" 
                                    VisibleIndex="21">
                                    <PropertiesComboBox DataSourceID="SqlDataSourceAutPersonal" 
                                        IncrementalFilteringMode="Contains" TextField="APE_CEDULA" ValueField="APE_ID" 
                                        ValueType="System.String">
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                            </Columns>
                            <SettingsBehavior ConfirmDelete="True" />
                            <Settings ShowFilterRow="True" ShowGroupPanel="True" />
                        </dx:ASPxGridView>
                   
            </td>
        </tr>
        <tr>
            <td>
                <asp:SqlDataSource ID="SqlDataSourceVehiculos" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    DeleteCommand="DELETE FROM [AUT_VEHICULOS] WHERE [AVE_ID] = @AVE_ID" InsertCommand="INSERT INTO [AUT_VEHICULOS] ([AMA_ID], [AMA_PLACA], [AMA_MARCA], [AVE_TIPO_VEHICULO], [AVE_CERT_HABILITACION], [AVE_SERIE_CHASIS], [AVE_FECHA_FABRICACION], [AVE_SOAT], [AVE_COMPANIA_SEGUROS], [AVE_VENCIMIENTO_SOAT], [AVE_VENCE_REVISION_TECNOMECANICA], [AVE_PAIS], [ATV_ID], [ACD_ID] , ACO_ID, ALI_ID, ACL_ID, ATC_ID, AVE_PESO_VACIO, APE_ID ) VALUES (@AMA_ID, @AMA_PLACA, @AMA_MARCA, @AVE_TIPO_VEHICULO, @AVE_CERT_HABILITACION, @AVE_SERIE_CHASIS, @AVE_FECHA_FABRICACION, @AVE_SOAT, @AVE_COMPANIA_SEGUROS, @AVE_VENCIMIENTO_SOAT, @AVE_VENCE_REVISION_TECNOMECANICA, @AVE_PAIS, @ATV_ID,  @ACD_ID,  @ACO_ID, @ALI_ID, @ACL_ID, @ATC_ID, @AVE_PESO_VACIO, @APE_ID )"
                    SelectCommand="SELECT ISNULL(CAST( DATEDIFF(DAY, getdate(),AVE_VENCIMIENTO_SOAT) AS INT),-1) AS DIAS_RESTANTES_SOAT, * FROM [AUT_VEHICULOS]"
                    UpdateCommand="UPDATE [AUT_VEHICULOS] SET AVE_ID_TRAILER = @AVE_ID_TRAILER, [AMA_ID] = @AMA_ID, [ACD_ID] = @ACD_ID , [AMA_PLACA] = @AMA_PLACA, [AMA_MARCA] = @AMA_MARCA, [AVE_TIPO_VEHICULO] = @AVE_TIPO_VEHICULO, [AVE_CERT_HABILITACION] = @AVE_CERT_HABILITACION, [AVE_SERIE_CHASIS] = @AVE_SERIE_CHASIS, [AVE_FECHA_FABRICACION] = @AVE_FECHA_FABRICACION, [AVE_SOAT] = @AVE_SOAT, [AVE_COMPANIA_SEGUROS] = @AVE_COMPANIA_SEGUROS, [AVE_VENCIMIENTO_SOAT] = @AVE_VENCIMIENTO_SOAT, [AVE_VENCE_REVISION_TECNOMECANICA] = @AVE_VENCE_REVISION_TECNOMECANICA, [AVE_PAIS] = @AVE_PAIS, [ATV_ID] = @ATV_ID,  ACO_ID = @ACO_ID, ALI_ID= @ALI_ID, ACL_ID = @ACL_ID, ATC_ID= @ATC_ID, AVE_PESO_VACIO= @AVE_PESO_VACIO, APE_ID= @APE_ID WHERE [AVE_ID] = @AVE_ID">
                    <DeleteParameters>
                        <asp:Parameter Name="AVE_ID" Type="Decimal" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="AMA_ID" Type="Decimal" />
                        <asp:Parameter Name="AMA_PLACA" Type="String" />
                        <asp:Parameter Name="AMA_MARCA" Type="String" />
                        <asp:Parameter Name="AVE_TIPO_VEHICULO" Type="String" />
                        <asp:Parameter Name="AVE_CERT_HABILITACION" Type="String" />
                        <asp:Parameter Name="AVE_SERIE_CHASIS" Type="String" />
                        <asp:Parameter DbType="Date" Name="AVE_FECHA_FABRICACION" />
                        <asp:Parameter Name="AVE_SOAT" Type="String" />
                        <asp:Parameter Name="AVE_COMPANIA_SEGUROS" Type="String" />
                        <asp:Parameter DbType="Date" Name="AVE_VENCIMIENTO_SOAT" />
                        <asp:Parameter DbType="Date" Name="AVE_VENCE_REVISION_TECNOMECANICA" />
                        <asp:Parameter Name="AVE_PAIS" Type="String" />
                        <asp:Parameter Name="ATV_ID" Type="Decimal" />
                        <asp:Parameter Name="AVE_ID_TRAILER" Type="Decimal" />
                        <asp:Parameter Name="ACO_ID" Type="Decimal" />
                        <asp:Parameter Name="ALI_ID" Type="Decimal" />
                        <asp:Parameter Name="ACL_ID" Type="Decimal" />
                        <asp:Parameter Name="ATC_ID" Type="Decimal" />
                        <asp:Parameter Name="AVE_PESO_VACIO" Type="Decimal" />
                        <asp:Parameter Name="APE_ID" Type="Decimal" />
                    </InsertParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="AMA_ID" Type="Decimal" />
                        <asp:Parameter Name="AMA_PLACA" Type="String" />
                        <asp:Parameter Name="AMA_MARCA" Type="String" />
                        <asp:Parameter Name="AVE_TIPO_VEHICULO" Type="String" />
                        <asp:Parameter Name="AVE_CERT_HABILITACION" Type="String" />
                        <asp:Parameter Name="AVE_SERIE_CHASIS" Type="String" />
                        <asp:Parameter DbType="Date" Name="AVE_FECHA_FABRICACION" />
                        <asp:Parameter Name="AVE_SOAT" Type="String" />
                        <asp:Parameter Name="AVE_COMPANIA_SEGUROS" Type="String" />
                        <asp:Parameter DbType="Date" Name="AVE_VENCIMIENTO_SOAT" />
                        <asp:Parameter DbType="Date" Name="AVE_VENCE_REVISION_TECNOMECANICA" />
                        <asp:Parameter Name="AVE_PAIS" Type="String" />
                        <asp:Parameter Name="ATV_ID" Type="Decimal" />
                        <asp:Parameter Name="AVE_ID" Type="Decimal" />
                        <asp:Parameter Name="ACD_ID" Type="Decimal" />
                        <asp:Parameter Name="AVE_ID_TRAILER" Type="Decimal" />
                        <asp:Parameter Name="ACO_ID" Type="Decimal" />
                        <asp:Parameter Name="ALI_ID" Type="Decimal" />
                        <asp:Parameter Name="ACL_ID" Type="Decimal" />
                        <asp:Parameter Name="ATC_ID" Type="Decimal" />
                        <asp:Parameter Name="AVE_PESO_VACIO" Type="Decimal" />
                        <asp:Parameter Name="APE_ID" Type="Decimal" />
                    </UpdateParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceMarcas" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    SelectCommand="SELECT [AMA_ID], [AMA_NOMBRE] FROM [AUT_MARCAS]"></asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceTipoVehiculos" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    SelectCommand="SELECT [ATV_ID], [ATV_NOMBRE] FROM [AUT_TIPO_VEHICULO]"></asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceAseguradoras" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    SelectCommand="SELECT [ACD_ID], [ACD_NOMBRE], [ACD_DIRECCION], [ACD_NIT], [ACD_TELEFONO], [ZON_ID] FROM [AUT_ASEGURADORAS]">
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSourceTrailer" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    SelectCommand="SELECT AVE_ID AS AVE_ID_TRAILER, AMA_PLACA FROM [AUT_VEHICULOS] WHERE ATV_ID = 5">
                </asp:SqlDataSource>
                <br />
                <asp:SqlDataSource ID="SqlDataSourceAutConfiguracion" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    
                    SelectCommand="SELECT [ACO_ID], [ACO_DESCRIPCION] FROM [AUT_CONFIGURACION]"></asp:SqlDataSource>
                <br />
                
                <asp:SqlDataSource ID="SqlDataSourceAutPersonal" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    
                    SelectCommand="SELECT [APE_ID], [APE_CEDULA] FROM [AUT_PERSONAL]"></asp:SqlDataSource>
                <br />

                <asp:SqlDataSource ID="SqlDataSourceAutLinea" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    
                    SelectCommand="SELECT [ALI_ID], [ALI_NOMBRE] FROM [AUT_LINEA]"></asp:SqlDataSource>
                <br />
                <asp:SqlDataSource ID="SqlDataSourceAutTipoCombustible" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    
                    
                    SelectCommand="SELECT [ATC_ID], [ATC_DESCRIPCION] FROM [AUT_TIPO_COMBUSTIBLE]"></asp:SqlDataSource>
                <br />
                <asp:SqlDataSource ID="SqlDataSourceAutColor" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                    
                    SelectCommand="SELECT [ACL_DESCRIPCION], [ACL_ID] FROM [AUT_COLOR]"></asp:SqlDataSource>
                <dx:ASPxButton ID="ASPxButton1" runat="server" Text="Exportar Vehiculos" Theme="PlasticBlue"
                    OnClick="ASPxButton1_Click">
                </dx:ASPxButton>
                <dx:ASPxGridViewExporter ID="ASPxGridViewExporterVehiculos" runat="server">
                </dx:ASPxGridViewExporter>
            </td>
        </tr>
    </table>
</asp:Content>
